<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
    <title>智能路线导航</title>
    <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
    <style>
        #map-container {
            width: 100%;
            height: 70vh;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin: 20px 0;
        }
        .nav-controls {
            background: rgba(255,255,255,0.9);
            backdrop-filter: blur(10px);
            padding: 20px;
            border-radius: 12px;
            margin-top: 15px;
        }
        #route-info {
            font-size: 16px;
            color: #2d3748;
            line-height: 1.6;
        }
        #route-info p {
            margin: 8px 0;
            padding: 12px;
            background: rgba(237, 242, 247, 0.3);
            border-radius: 6px;
        }
        @media (max-width: 768px) {
            #map-container {
                height: 65vh;
            }
            .nav-controls {
                padding: 15px;
            }
            #route-info {
                font-size: 14px;
            }
        }
        /* 新增触控反馈效果 */
        .map-wrapper {
            position: relative;
            overflow: hidden;
        }
        
        .map-touch-shield {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1000;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>智能路线导航</h1>
        <div id="map-container"></div>
        <div class="nav-controls">
            <div id="route-info"></div>
        </div>
    </div>

    <script src="https://api.map.baidu.com/api?v=3.0&type=webgl&ak=47jXQbiwPNWVY5GgVPUJYpOiHG5YhBcr" type="text/javascript"></script>
    <script>
        const urlParams = new URLSearchParams(window.location.search);
        const startPoint = urlParams.get('start').split(',');
        const endPoint = urlParams.get('end').split(',');

        const map = new BMapGL.Map('map-container');
        map.centerAndZoom(new BMapGL.Point(startPoint[1], startPoint[0]), 13);
        map.enableScrollWheelZoom(true);

        const driving = new BMapGL.DrivingRoute(map, {
            renderOptions: {
                map: map,
                autoViewport: true,
                panel: 'route-info'
            },
            onSearchComplete: (results) => {
                if (driving.getStatus() === BMAP_STATUS_SUCCESS) {
                    const plan = results.getPlan(0);
                    document.getElementById('route-info').innerHTML = `
                        <p>总里程: ${plan.getDistance(true)}</p>
                        <p>预计时间: ${plan.getDuration(true)}</p>
                    `;
                }
            }
        });

        driving.search(
            new BMapGL.Point(startPoint[1], startPoint[0]),
            new BMapGL.Point(endPoint[1], endPoint[0])
        );

        // 移动端触摸事件处理
        let touchStart = null;
        map.addEventListener('touchstart', (e) => {
            touchStart = e.changedTouches[0].clientY;
        });
        map.addEventListener('touchend', (e) => {
            const touchEnd = e.changedTouches[0].clientY;
            if (Math.abs(touchEnd - touchStart) > 100) {
                map.reset();
            }
        });
    </script>
</body>
</html>